package com.nlx.notes.module.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nlx.notes.module.bean.dto.querydb.StatisticsQueryDTO;
import com.nlx.notes.module.bean.vo.statistics.CategoryMonthStatisticsVO;
import com.nlx.notes.module.entity.CategoryMonthStatistics;
import com.nlx.notes.module.mapper.CategoryMonthStatisticsMapper;
import com.nlx.notes.module.service.ICategoryMonthStatisticsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 月度分类统计 服务实现类
 * </p>
 *
 * @author nlx
 * @since 2025-06-08
 */
@Service
public class CategoryMonthStatisticsServiceImpl extends ServiceImpl<CategoryMonthStatisticsMapper, CategoryMonthStatistics> implements ICategoryMonthStatisticsService {

    @Override
    public List<CategoryMonthStatisticsVO> findByMonth(StatisticsQueryDTO statisticsQueryDTO) {
        return this.getBaseMapper().findByMonth(statisticsQueryDTO);

    }

    @Override
    public void removeCategory(String month,Long bookId, Long userId) {
        if(StrUtil.isEmpty(month) || null == userId || null == bookId){
            return ;
        }
        this.getBaseMapper().delete(Wrappers.lambdaUpdate(CategoryMonthStatistics.class)
                .eq(CategoryMonthStatistics::getUserId,userId)
                        .eq(CategoryMonthStatistics::getBookId,bookId)
                .eq(CategoryMonthStatistics::getMothDate,month));
    }
}
